//
//  XLIncomeRecordBaseVC.m
//  XiangLove
//
//  Created by 李传坤 on 2018/7/31.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLIncomeRecordBaseVC.h"
#import <VTMagic.h>
#import "XLGetGiftRecordVC.h"
#import "XLC2CVideoIncomeVC.h"
#import "XLOtherIncomeVC.h"

@interface XLIncomeRecordBaseVC ()<VTMagicViewDelegate,VTMagicViewDataSource>

@property (nonatomic, strong) VTMagicController *magicController;
@property (nonatomic, strong) NSArray           *menuArray;
@property (nonatomic, strong) NSArray           *menuConfigArray;
@property (nonatomic, assign) NSUInteger         currentShowingPageId;

@end
@implementation XLIncomeRecordBaseVC
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.menuConfigArray = [self getCommonMenuConfig];
    [self generateTestData];
    self.fd_prefersNavigationBarHidden = YES;
    [self initMagicView];
    
    
    
//   [self.magicController.magicView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
}
-(void)initMagicView
{
    _magicController = [[VTMagicController alloc] init];
    _magicController.view.translatesAutoresizingMaskIntoConstraints = NO;
    _magicController.magicView.navigationColor = RGB_HEX(0xffffff);
    _magicController.magicView.sliderColor = HEXCOLOR(0x000000);//滑动条
    _magicController.magicView.sliderHeight = 2;
    _magicController.magicView.itemSpacing = 27;
    _magicController.magicView.itemScale = 1.143;
    _magicController.magicView.displayCentered = YES;
    _magicController.magicView.switchStyle = VTSwitchStyleDefault;
    _magicController.magicView.layoutStyle = VTLayoutStyleCenter;
    if (IS_IPHONE_X) {
        _magicController.magicView.navigationHeight = 88.f;
    }else{
        _magicController.magicView.navigationHeight = 64.f;
    }
    
    _magicController.magicView.navigationInset = UIEdgeInsetsMake(10, 0, 0, 0);
    _magicController.magicView.againstStatusBar = NO;
    _magicController.magicView.sliderExtension = 2;
    _magicController.magicView.sliderOffset = -5;
    _magicController.magicView.dataSource = self;
    _magicController.magicView.delegate = self;
    _magicController.magicView.separatorColor = [UIColor groupTableViewBackgroundColor];
    [self addChildViewController:_magicController];
    [self.view addSubview:_magicController.view];
    [_magicController.magicView reloadData];
    [_magicController.magicView switchToPage:0 animated:NO];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(10, 20, 50, 40);
    if (IS_IPHONE_X) {
        backButton.frame = CGRectMake(10, 40, 50, 40);
    }
    [backButton addTarget:self action:@selector(back1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    [backButton setImage:[UIImage imageNamed:@"common_nav_btn_back_n"] forState:UIControlStateNormal];
    
}
- (void)back1{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - DataDelegate
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return _menuArray;
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:HEXCOLOR(0x6A6978) forState:UIControlStateNormal];
        [menuItem setTitleColor:HEXCOLOR(0x000000) forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont systemFontOfSize:17.f];
    }
    return menuItem;
}
- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    NSString *title = self.menuArray[pageIndex];
    if ([title isEqualToString:@"礼物"]) {
        XLGetGiftRecordVC *vc = [magicView dequeueReusablePageWithIdentifier:F(@"%@%zd", NSStringFromClass([XLGetGiftRecordVC class]), pageIndex)];
        if (vc == nil) {
            vc = [[XLGetGiftRecordVC alloc] init];
        }
        return vc;
    }else if ([title isEqualToString:@"1V1聊天"]) {
        XLC2CVideoIncomeVC *vc = [magicView dequeueReusablePageWithIdentifier:F(@"%@%zd", NSStringFromClass([XLC2CVideoIncomeVC class]), pageIndex)];
        if (vc == nil) {
            vc = [[XLC2CVideoIncomeVC alloc] init];
            
        }
        return vc;
    }
    else{
        XLOtherIncomeVC *vc = [magicView dequeueReusablePageWithIdentifier:F(@"%@%zd", NSStringFromClass([XLOtherIncomeVC class]), pageIndex)];
        if (vc == nil) {
            vc = [[XLOtherIncomeVC alloc] init];
        }
        return vc;
    }
}

- (void)magicView:(VTMagicView *)magicView viewDidAppear:(__kindof UIViewController *)viewController atPage:(NSUInteger)pageIndex {
    self.currentShowingPageId = pageIndex;
    NSLog(@"%zd", self.currentShowingPageId);
}

- (void)generateTestData {
    NSMutableArray *menu = [NSMutableArray array];
    for (NSDictionary *dic in self.menuConfigArray) {
        [menu addObject:dic[@"title"]];
    }
    _menuArray = menu.copy;
}

- (NSArray *)getCommonMenuConfig
{
    NSArray *commnMenu;
    commnMenu = @[
                  @{@"title": @"礼物"},
                  @{@"title": @"1V1聊天"},
                  @{@"title": @"其他"},
                  ];
    
    return commnMenu;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
